// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Core.Reindex;

public sealed partial class RemoteSource
{
	/// <summary>
	/// <para>The remote connection timeout.<br/>Defaults to 30 seconds.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("connect_timeout")]
	public Elastic.Clients.Elasticsearch.Serverless.Duration? ConnectTimeout { get; set; }

	/// <summary>
	/// <para>An object containing the headers of the request.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("headers")]
	public IDictionary<string, string>? Headers { get; set; }

	/// <summary>
	/// <para>The URL for the remote instance of Elasticsearch that you want to index from.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("host")]
	public string Host { get; set; }

	/// <summary>
	/// <para>The password to use for authentication with the remote host.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("password")]
	public string? Password { get; set; }

	/// <summary>
	/// <para>The remote socket read timeout. Defaults to 30 seconds.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("socket_timeout")]
	public Elastic.Clients.Elasticsearch.Serverless.Duration? SocketTimeout { get; set; }

	/// <summary>
	/// <para>The username to use for authentication with the remote host.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("username")]
	public Elastic.Clients.Elasticsearch.Serverless.Username? Username { get; set; }
}

public sealed partial class RemoteSourceDescriptor : SerializableDescriptor<RemoteSourceDescriptor>
{
	internal RemoteSourceDescriptor(Action<RemoteSourceDescriptor> configure) => configure.Invoke(this);

	public RemoteSourceDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Duration? ConnectTimeoutValue { get; set; }
	private IDictionary<string, string>? HeadersValue { get; set; }
	private string HostValue { get; set; }
	private string? PasswordValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Duration? SocketTimeoutValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Username? UsernameValue { get; set; }

	/// <summary>
	/// <para>The remote connection timeout.<br/>Defaults to 30 seconds.</para>
	/// </summary>
	public RemoteSourceDescriptor ConnectTimeout(Elastic.Clients.Elasticsearch.Serverless.Duration? connectTimeout)
	{
		ConnectTimeoutValue = connectTimeout;
		return Self;
	}

	/// <summary>
	/// <para>An object containing the headers of the request.</para>
	/// </summary>
	public RemoteSourceDescriptor Headers(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		HeadersValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	/// <summary>
	/// <para>The URL for the remote instance of Elasticsearch that you want to index from.</para>
	/// </summary>
	public RemoteSourceDescriptor Host(string host)
	{
		HostValue = host;
		return Self;
	}

	/// <summary>
	/// <para>The password to use for authentication with the remote host.</para>
	/// </summary>
	public RemoteSourceDescriptor Password(string? password)
	{
		PasswordValue = password;
		return Self;
	}

	/// <summary>
	/// <para>The remote socket read timeout. Defaults to 30 seconds.</para>
	/// </summary>
	public RemoteSourceDescriptor SocketTimeout(Elastic.Clients.Elasticsearch.Serverless.Duration? socketTimeout)
	{
		SocketTimeoutValue = socketTimeout;
		return Self;
	}

	/// <summary>
	/// <para>The username to use for authentication with the remote host.</para>
	/// </summary>
	public RemoteSourceDescriptor Username(Elastic.Clients.Elasticsearch.Serverless.Username? username)
	{
		UsernameValue = username;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ConnectTimeoutValue is not null)
		{
			writer.WritePropertyName("connect_timeout");
			JsonSerializer.Serialize(writer, ConnectTimeoutValue, options);
		}

		if (HeadersValue is not null)
		{
			writer.WritePropertyName("headers");
			JsonSerializer.Serialize(writer, HeadersValue, options);
		}

		writer.WritePropertyName("host");
		JsonSerializer.Serialize(writer, HostValue, options);
		if (PasswordValue is not null)
		{
			writer.WritePropertyName("password");
			JsonSerializer.Serialize(writer, PasswordValue, options);
		}

		if (SocketTimeoutValue is not null)
		{
			writer.WritePropertyName("socket_timeout");
			JsonSerializer.Serialize(writer, SocketTimeoutValue, options);
		}

		if (UsernameValue is not null)
		{
			writer.WritePropertyName("username");
			JsonSerializer.Serialize(writer, UsernameValue, options);
		}

		writer.WriteEndObject();
	}
}